package com.example.archive.entity;

import org.springframework.data.annotation.Id;
import org.springframework.data.elasticsearch.annotations.Document;
import org.springframework.data.elasticsearch.annotations.Field;
import org.springframework.data.elasticsearch.annotations.FieldType;
import com.fasterxml.jackson.annotation.JsonFormat;
import lombok.Data;

import java.util.Date;

/**
 * Elasticsearch档案文档实体
 * 用于在Elasticsearch中存储和搜索档案信息
 * 使用IK中文分词器进行中文分词处理
 */
@Data
@Document(indexName = "archives")
public class ArchiveDocument {
    
    @Id
    private String id;
    
    @Field(type = FieldType.Integer)
    private Integer archiveId;
    
    @Field(type = FieldType.Text, analyzer = "ik_max_word", searchAnalyzer = "ik_smart")
    private String title;
    
    @Field(type = FieldType.Keyword)
    private String filePath;
    
    @Field(type = FieldType.Text, analyzer = "ik_max_word", searchAnalyzer = "ik_smart")
    private String originalFilename;
    
    @Field(type = FieldType.Text, analyzer = "ik_max_word", searchAnalyzer = "ik_smart")
    private String physicalLocation;
    
    @Field(type = FieldType.Keyword)
    private String archiveType;
    
    @Field(type = FieldType.Keyword)
    private String securityLevel;
    
    @Field(type = FieldType.Keyword)
    private String visibleScope;
    
    @Field(type = FieldType.Text, analyzer = "ik_max_word", searchAnalyzer = "ik_smart")
    private String autoCategory;
    
    @Field(type = FieldType.Text, analyzer = "ik_max_word", searchAnalyzer = "ik_smart")
    private String autoTags;
    
    @Field(type = FieldType.Text, analyzer = "ik_max_word", searchAnalyzer = "ik_smart")
    private String ocrContent;
    
    @Field(type = FieldType.Date, format = {}, pattern = "yyyy-MM-dd HH:mm:ss")
    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8")
    private Date receiptTime;
    
    @Field(type = FieldType.Integer)
    private Integer creatorId;
    
    @Field(type = FieldType.Keyword)
    private String status;
    
    @Field(type = FieldType.Date, format = {}, pattern = "yyyy-MM-dd HH:mm:ss")
    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8")
    private Date createdAt;
    
    @Field(type = FieldType.Date, format = {}, pattern = "yyyy-MM-dd HH:mm:ss")
    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8")
    private Date updatedAt;
    
    @Field(type = FieldType.Integer)
    private Integer lastModifiedBy;
    
    @Field(type = FieldType.Date, format = {}, pattern = "yyyy-MM-dd HH:mm:ss")
    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8")
    private Date lastModifiedAt;
    
    /**
     * 从Archive实体转换为ArchiveDocument
     */
    public static ArchiveDocument fromArchive(Archive archive) {
        ArchiveDocument document = new ArchiveDocument();
        document.setId(archive.getArchiveId().toString());
        document.setArchiveId(archive.getArchiveId());
        document.setTitle(archive.getTitle());
        document.setFilePath(archive.getFilePath());
        document.setOriginalFilename(archive.getOriginalFilename());
        document.setPhysicalLocation(archive.getPhysicalLocation());
        document.setArchiveType(archive.getArchiveType());
        document.setSecurityLevel(archive.getSecurityLevel());
        document.setVisibleScope(archive.getVisibleScope());
        document.setAutoCategory(archive.getAutoCategory());
        document.setAutoTags(archive.getAutoTags());
        document.setOcrContent(archive.getOcrContent());
        document.setReceiptTime(archive.getReceiptTime());
        document.setCreatorId(archive.getCreatorId());
        document.setStatus(archive.getStatus());
        document.setCreatedAt(archive.getCreatedAt());
        document.setUpdatedAt(archive.getUpdatedAt());
        document.setLastModifiedBy(archive.getLastModifiedBy());
        document.setLastModifiedAt(archive.getLastModifiedAt());
        return document;
    }
} 